home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / pmpsrc11.zip / TIMER.ASM < prev    next >
Assembly Source File  |  1991-02-02  |  3KB  |  160 lines

  1. ;
  2. ;    TIMER.ASM
  3. ;
  4. ;        Low level assembly transmit and receive routines.
  5. ;
  6. ;    July, 1989
  7. ;    Andrew C. Payne
  8. ;
  9. ;    This module implements:
  10. ;
  11. ;               timer()          - returns the current timer state
  12. ;        transit(time) - waits until time given, and causes and output
  13. ;                transition
  14. ;        waittrans(til)  Waits until the time given for a transition,
  15. ;                returns the time of the transition
  16. ;        waituntil(t)    Waits until time given
  17. ;
  18. ;    Modifications:
  19. ;        090589 - added 'waittrans' (acp)
  20. ;
  21.  
  22.     DOSSEG
  23.     .MODEL  LARGE        ; 'C' Large Memory Model
  24.  
  25. ; ----- Equates
  26.  
  27. TIMER1    EQU    040H        ; base I/O Port for timer
  28. TIMER2    EQU    TIMER1+3    ; port to latch count
  29.  
  30. ; ----- Externals
  31.     GLOBAL    _TXPort:word,_TXBit:byte
  32.     GLOBAL    _RXPort:word,_RXBit:byte
  33.  
  34. ; ----- Macros
  35.  
  36. READTIME    MACRO        ; reads BIOS timer into AX
  37.  
  38.     MOV    AL,0        ; latch count
  39.     OUT    TIMER2,AL
  40.  
  41.     IN    AL,TIMER1    ; read LSB
  42.     XCHG    AL,AH        ; save
  43.     IN    AL,TIMER1    ; read MSB
  44.     XCHG    AL,AH        ; make order correct
  45.     ENDM
  46.  
  47. ; ----- Code Segment
  48.     .CODE
  49.  
  50. ; timer()
  51. ;    Returns current value of Counter #0
  52. ;
  53.     PUBLIC _timer
  54. _timer    PROC
  55.     READTIME        ; read the current time into AX
  56.     RET
  57. _timer    ENDP
  58.  
  59. ; waituntil(time)
  60. ;
  61. ;    Waits until the time given.
  62. ;
  63.     PUBLIC    _waituntil
  64. _waituntil PROC
  65.     ARG    EndTime:WORD
  66.  
  67.     PUSH    BP
  68.     MOV    BP,SP        ; set up stack frame
  69.  
  70. ; wait till ending time
  71.     MOV    BX,[EndTime]    ; get into a register
  72.  
  73. wuloop:
  74.     READTIME        ; get current time
  75.     SUB    AX,BX
  76.     JNS    tloop        ; wait until passed
  77.  
  78.     POP    BP        ; restore stack frame
  79.     RET
  80.  
  81. _waituntil ENDP
  82.  
  83.  
  84. ;
  85. ; transit(at)
  86. ;    Causes an output TX data transition to occur at the time given
  87. ;
  88.     PUBLIC    _transit
  89. _transit PROC
  90.     ARG    EndTime:WORD
  91.  
  92.     PUSH    BP
  93.     MOV    BP,SP        ; set up stack frame
  94.  
  95. ; wait till ending time
  96.     MOV    BX,[EndTime]    ; get into a register
  97.  
  98. tloop:
  99.     READTIME        ; get current time
  100.     SUB    AX,BX
  101.     JNS    tloop        ; wait until passed
  102.  
  103. ; make transition
  104.     MOV    DX,[_TXPort]
  105.     IN    AL,DX        ; get current port value
  106.     XOR    AL,[_TXBit]    ; invert TX data bit
  107.     OUT    DX,AL        ; write it out
  108.  
  109.     READTIME        ; read time of transition
  110.  
  111.     POP    BP        ; restore stack frame
  112.     RET
  113.  
  114. _transit ENDP
  115.  
  116. ;
  117. ; waittrans(till)
  118. ;    Waits until the time given for a transition, returns the time of the
  119. ;    transition.  The time return will equal 'till' if no tranisition
  120. ;    occurred.
  121. ;
  122. ;
  123.  
  124.     PUBLIC    _waittrans
  125. _waittrans PROC
  126.     ARG    EndTime:WORD
  127.  
  128.     PUSH    BP
  129.     MOV    BP,SP        ; set up stack frame
  130.  
  131.     MOV    BX,[EndTime]    ; get ending time into a register
  132.  
  133.     MOV    DX,[_RXPort]    ; get input port
  134.     IN    AL,DX        ; read current value
  135.     MOV    CL,AL        ; save
  136.  
  137. waitt:
  138.     IN    AL,DX        ; read current value
  139.     XOR    AL,CL        ; compare bits
  140.     AND    AL,[_RXBit]    ; mask the RX data bit
  141.     JNZ    waitt1        ; got transition, return time
  142.  
  143. ; read current time, check to see if we are done yet or not
  144.     READTIME
  145.     SUB    AX,BX
  146.     JNS    waitt        ; loop until time out
  147.  
  148. ; time out, got no transition
  149.     MOV    AX,BX        ; return ending time parameter
  150.     JMP    waitt2        ; all done
  151.  
  152. ; got a transition, return the current time
  153. waitt1:
  154.     READTIME
  155. waitt2:
  156.     POP    BP
  157.     RET
  158.  
  159. _waittrans ENDP
  160.     END